package qiyu.live.bank.api.service.impl;

import com.alibaba.fastjson2.JSON;
import org.apache.dubbo.config.annotation.DubboReference;
import org.qiyu.live.bank.dto.PayOrderDTO;
import org.qiyu.live.bank.interfaces.IPayOrderRpc;
import org.springframework.stereotype.Service;
import qiyu.live.bank.api.service.IPayNotifyService;
import qiyu.live.bank.api.vo.WXNotifyVO;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-11-07
 * Time: 15:53
 */
@Service
public class PayNotifyServiceImpl implements IPayNotifyService {

    @DubboReference
    private IPayOrderRpc payOrderRpc;

    @Override
    public String notifyHandler(String param) {
        // 1. 转化成具体的对象,找到订单
        WXNotifyVO wxNotifyVO = JSON.parseObject(param, WXNotifyVO.class);
        PayOrderDTO payOrderDTO = new PayOrderDTO();
        payOrderDTO.setOrderId(wxNotifyVO.getOrderId());
        payOrderDTO.setUserId(wxNotifyVO.getUserId());
        // 2. 远程调用PayOrderRpc修改订单状态,支付成功之后,交给其他业务进行处理
        // 比如支付成功之后,通知用户支付成功的消息
        return payOrderRpc.payNotify(payOrderDTO) ? "success" : "fail";
    }
}